Skip to content

fix(session): accept value matching any band on multi-RANGE DATA#16

Merged
ale-rinaldi merged 1 commit into
mainfrom
fix/issue-2-multi-band-ranges
May 15, 2026
Merged

fix(session): accept value matching any band on multi-RANGE DATA#16
ale-rinaldi merged 1 commit into
mainfrom
fix/issue-2-multi-band-ranges

Conversation

@ale-rinaldi

Copy link
Copy Markdown
Contributor

Closes #2.

What changed

validateAgainstRange now consults Data.Ranges (the full set of <RANGE> children, populated by the parser since the audit-D2 changes) and accepts a value matching any band, instead of only the last <RANGE> declared. The single-band Data.Range is still read as a fallback for DATA with exactly one <RANGE>.

Per-band checks remain the same as before — Min ≤ value ≤ Max and (value − Min) mod Step == 0 when Step > 1 — they're just run against each band in turn until one matches.

The error path branches:

  • single-band: same wording as before (out of catalog range [Min, Max] / violates step=K (offsets from Min allowed)) so existing tooling/error-parsing keeps working;
  • multi-band: lists every declared band (not in any of catalog bands [a,b step c] [d,e step f] …) so the operator can see what the catalog actually allows.

Tests

pkg/session/range_internal_test.go (new, in-package so the private function is callable). Covers:

  • single-band: in-range, lower bound, upper bound, below, above, step violation;
  • multi-band: every band's lower / mid / upper accepted; below all rejected; above all rejected; value inside one band's [Min, Max] but violating its Step rejected (no fallthrough);
  • multi-band error string enumerates every band exactly;
  • STRING / ENUM* TIPOs skipped (existing behaviour preserved);
  • DATA with neither Range nor Ranges is a no-op.

The catalog parser side was already correct (commit 5e28fc9 added Ranges and the loop that appends every <RANGE> child); this PR only fixes the validator that ignored it.

Scope

I did not extend the test fixture testdata/us/TEST-VB0-a with a multi-band DATA + an end-to-end Session.Set integration test. The internal-package tests exercise the failing function directly with a synthesised *catalog.Data, which is enough to lock in the fix; a fixture-level integration test is a reasonable follow-up if we want to assert the parser+validator interaction together.

🤖 Generated with Claude Code

validateAgainstRange used to read only Data.Range (the single-band
field kept for back-compat) and refuse anything outside it. For DATA
declarations with several <RANGE> children — piecewise-valid bands
with different step sizes, e.g. VLineaPrimario_1 declaring
[50..499 step 1] / [500..4990 step 10] / [5000..49900 step 100] /
[50000..500000 step 1000] — the validator effectively saw only the
last band and rejected legitimate values from any other.

The catalog parser already populates Data.Ranges with every <RANGE>
child (kept the back-compat Data.Range = first band on the side).
Switch the validator to consult Data.Ranges when populated, fall back
to the single Range otherwise, and accept the value if it sits inside
*any* band — both bounds and step alignment checked per-band.

The error path now distinguishes single-band (preserves the original
"out of catalog range [Min, Max]" wording for callers/operators used
to it) from multi-band (lists every band so the operator can see
what's actually allowed).

Tests cover: single-band accept/reject/step-violation;
multi-band accept inside each band, reject below/above, reject when
value is inside one band's bounds but violates its step;
non-numeric TIPOs skipped; absent ranges no-op.

Closes #2

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ale-rinaldi ale-rinaldi merged commit 9f2f833 into main May 15, 2026
2 checks passed
@ale-rinaldi ale-rinaldi deleted the fix/issue-2-multi-band-ranges branch May 15, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-band DATA: parser keeps only the last <RANGE> child, validator rejects values in earlier bands

1 participant